﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BlueBoss2
{
    public partial class WatchItemForm : Form
    {
        Form1 _parentForm = null;

        public WatchItemForm(Form1 f, String DeviceName)
        {
            InitializeComponent();
            this._parentForm = f;
            lblDeviceName.Text = DeviceName;

        }

        public WatchItemForm(Form1 f, WatchItem item)
        {
            InitializeComponent();
            this._parentForm = f;

            lblDeviceName.Text = item.DeviceName;
            tbxAlertMessage.Text = item.AlertMessage;
            tbxPicturePath.Text = item.ImagePath;
            tbxProgramPath.Text = item.ProgramPath;
            this._parentForm.Enabled = true;
            
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            WatchItem item = new WatchItem(lblDeviceName.Text);

            //check input fields
            if (tbxAlertMessage.Text != String.Empty)
            {
                item.AlertMessage = tbxAlertMessage.Text;
            }

            if (tbxPicturePath.Text != String.Empty)
            {
                item.ImagePath = tbxPicturePath.Text;
            }

            if (tbxProgramPath.Text != String.Empty)
            {
                item.ProgramPath = tbxProgramPath.Text;
            }

            _parentForm.AddWatchItem(item);
            _parentForm.Enabled = true;
            this.Close();
        }

        private void btnPictureBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog j = new OpenFileDialog();

            j.InitialDirectory = "c:\\";
            j.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";
            j.FilterIndex = 2;
            j.RestoreDirectory = true;
            j.ShowDialog();
            tbxPicturePath.Text = j.FileName;
        }

        private void btnProgramBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog n = new OpenFileDialog();
            n.InitialDirectory = "c:\\";
            n.Filter = "Executables(*.exe;*.bat)|*.exe;*.bat";
            n.FilterIndex = 2;
            n.RestoreDirectory = true;
            n.ShowDialog();
            tbxProgramPath.Text = n.FileName;
        }
    }
}
